package com.geekydoo.commands;

import generated.TaskType;

import java.util.List;
import java.util.logging.Logger;

import com.geekydoo.GeekyDooException;
import com.geekydoo.InputOutputHandler;
import com.rits.cloning.Cloner;

/**
 * The purpose of this class is to, by its instantiation, cause the
 * ActionHandler to switch to the task list that it was using before the last
 * modifying command.
 * 
 * @author Patrick Dutch
 */
public class UndoCommand implements Command {

	private static Logger logger = Logger.getLogger("geekydoo");

	// The list of all task objects managed by the program
	private List<TaskType> taskList;

	// List of all tasks as it was before the undo was executed
	private static List<TaskType> preExecutionList;

	// Messages printed by the undo command
	private static final String MSG_UNDONE = "The most recent modifying command has been undone.";

	public void execute(List<TaskType> tasks) throws GeekyDooException {
		taskList = tasks;
		Cloner cloner = new Cloner();
		preExecutionList = cloner.deepClone(taskList);

		logger.info("Preparing to revert to old version of task list");
		InputOutputHandler.printToConsole(MSG_UNDONE, true, false);
	}

	public boolean isListModified() {
		return true;
	}

	public List<TaskType> getPreExecutionList() {
		return preExecutionList;
	}

}
